<?php

namespace App\Http\Resources;

use App\Enums\WorkTicketRatingEnum;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/**
 * @OA\Schema(
 *     schema="WorkTicketRatingResource",
 *     title="工单评价资源",
 *     description="工单评价信息",
 *     @OA\Property(property="id", type="integer", description="评价ID", example=1),
 *     @OA\Property(property="work_ticket_id", type="integer", description="工单ID", example=1),
 *     @OA\Property(property="work_user_id", type="integer", description="维护人员ID", example=1),
 *     @OA\Property(property="school_user_id", type="integer", description="学校用户ID", example=1),
 *     @OA\Property(property="score", type="integer", description="评分", example=100),
 *     @OA\Property(property="score_text", type="string", description="评分文本", example="满意"),
 *     @OA\Property(property="content", type="string", description="评价内容", example="师傅技术很好，服务态度也不错"),
 *     @OA\Property(property="created_at", type="string", format="date-time", description="创建时间", example="2025-01-01 12:00:00"),
 *     @OA\Property(property="updated_at", type="string", format="date-time", description="更新时间", example="2025-01-01 12:00:00")
 * )
 * @mixin \App\Models\WorkTicketRating
 */
class WorkTicketRatingResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'work_ticket_id' => $this->work_ticket_id,
            'work_user_id' => $this->work_user_id,
            'work_user_name' => $this->workUser?->real_name,
            'school_user_id' => $this->school_user_id,
            'school_user_name' => $this->schoolUser?->real_name,
            'score' => $this->score,
            'score_text' => WorkTicketRatingEnum::getKey($this->score),
            'content' => $this->content,
            'created_at' => $this->created_at?->toDateTimeString(),
            'updated_at' => $this->updated_at?->toDateTimeString(),
        ];
    }
} 